import React, { useState, useEffect } from 'react';
import moment from 'moment';

export default function Clock() {
  const [value, setValue] = useState(moment().format('YYYY-MM-DD HH:mm:ss'));
  useEffect(() => {
    let time = setInterval(() => {
      setValue(moment().format('YYYY-MM-DD HH:mm:ss'));
    }, 1000);
    return () => {
      clearInterval(time);
      time = null;
    };
  }, []);
  return <span>{value}</span>;
}
